<?xml version="1.0" encoding="utf-8" ?> 
<xs:schema targetNamespace="http://criticalsystems.co.uk/schemas/instrumentation/02/2009"
                  elementFormDefault="qualified"
                  xmlns="http://criticalsystems.co.uk/schemas/instrumentation/02/2009"
                  xmlns:ci="http://criticalsystems.co.uk/schemas/instrumentation/02/2009"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="systemInformation" type="SystemInformation"/>
  <xs:complexType name="SystemInformation">
    <xs:sequence>
      <xs:element name="description" type="Description" minOccurs="0"/>
      <xs:element name="subsystems">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="subsystem" type="Subsystem" minOccurs="1" maxOccurs="unbounded">
            </xs:element>
          </xs:sequence>
        </xs:complexType>
        <xs:key name="subsystemKey">
          <xs:selector xpath="ci:subsystem"/>
          <xs:field xpath="@name"/>
        </xs:key>
        <xs:unique name="subsystemCategoryIdUnique">
          <xs:selector xpath="ci:subsystem"/>
          <xs:field xpath="@categoryId"/>
        </xs:unique>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="name" type="Name" use="required"/>
    <xs:attribute name="displayName" type="displayName" use="optional"/>
    <xs:attribute name="eventLog" type="Name" use="optional" default="Application"/>
    <xs:attribute name="version" type="Version" use="required"/>
  </xs:complexType>
  <xs:complexType name="Subsystem">
    <xs:sequence>
      <xs:element name="description" type="Description" minOccurs="0"/>
      <xs:element name="dependencies" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="subsystem" type="SubsystemReference" minOccurs="1" maxOccurs="unbounded">
              <xs:keyref name="subsystemKeyReference" refer="subsystemKey">
                <xs:selector xpath="."/>
                <xs:field xpath="@name"/>
              </xs:keyref>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="name" type="Name" use="required"/>
    <xs:attribute name="categoryId" type="CategoryId" use="required"/>
    <xs:attribute name="type" type="SubsystemType" use="required"/>
  </xs:complexType>
  <xs:complexType name="SubsystemReference">
    <xs:attribute name="name" type="Name" use="required"/>
  </xs:complexType>
  <xs:simpleType name="Name">
    <xs:restriction base="xs:token">
      <xs:pattern value="[\w]{1,25}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="displayName">
    <xs:restriction base="xs:string">
      <xs:pattern value="[\w\s]{1,50}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Version">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Description">
    <xs:restriction base="xs:string"/>
  </xs:simpleType>
  <xs:simpleType name="CategoryId">
    <xs:restriction base="xs:unsignedShort">
      <xs:minInclusive value="1"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="SubsystemType">
    <xs:restriction base="xs:token">
      <xs:enumeration value="ConsoleApplication"/>
      <xs:enumeration value="WindowsApplication"/>
      <xs:enumeration value="ComLibrary"/>
      <xs:enumeration value="ComServer"/>
      <xs:enumeration value="WindowsService"/>
      <xs:enumeration value="WebApplication"/>
      <xs:enumeration value="WebService"/>
      <xs:enumeration value="Library"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
